package com.taobaolite.cart_has_items;

import com.taobaolite.item.Item;
import com.taobaolite.user.guest.Guest;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;
import java.util.Objects;

@Embeddable
public class CartPK implements Serializable {
    @ManyToOne
    @JoinColumn(name = "itemId")
    private Item item;

    @ManyToOne
    @JoinColumn(name = "guestId")
    private Guest guest;

    public CartPK(Item item, Guest guest) {
        this.item = item;
        this.guest = guest;
    }

    public CartPK() {}

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CartPK cartPK = (CartPK) o;
        return item.equals(cartPK.item) && guest.equals(cartPK.guest);
    }

    @Override
    public int hashCode() {
        return Objects.hash(item, guest);
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Guest getGuest() {
        return guest;
    }

    public void setGuest(Guest guest) {
        this.guest = guest;
    }
}
